export function getStateInfo(act_state_id) {
  if (act_state_id == 0) {
    return "草稿";
  } else if (act_state_id == 1) {
    return "待审核";
  } else if (act_state_id == 2) {
    return "被退回";
  } else if (act_state_id == 3) {
    return "被撤回";
  } else if (act_state_id == 4) {
    return "已审核";
  } else if (act_state_id == 5) {
    return "已关闭";
  }else if (act_state_id == 6) {
    return "申请办结";
  }
}
export function concatChildren(list,keyname){
  if(list){
    list.forEach((item,index)=>{
      if(item){
        if(item.name)item.alias = item.name
        if(keyname&&!item[keyname]){
          item[keyname] = item.id
        }
        if(item.users&&item.children){
          item.users=item.users.item.children
        }else if(item.children){
          item.users=item.children
        }
        delete item.children
        if(item.users){
          concatChildren(item.users)
        }else{
          delete item.users
        }
      }else{
        delete list[index]
      }
    })
  }
}
/**
 * 构造树型结构数据
 * @param {*} data 数据源
 * @param {*} id id字段 默认 'id'
 * @param {*} parentId 父节点字段 默认 'parentId'
 * @param {*} children 孩子节点字段 默认 'children'
 */
export function handleTree(data, id, parentId, children) {
  let config = {
    id: id || 'id',
    parentId: parentId || 'parentId',
    childrenList: children || 'children'
  };

  var childrenListMap = {};
  var nodeIds = {};
  var tree = [];

  for (let d of data) {

    let parentId = d[config.parentId];
    if (childrenListMap[parentId] == null) {
      childrenListMap[parentId] = [];
    }
    nodeIds[d[config.id]] = d;
    childrenListMap[parentId].push(d);
  }
  for (let d of data) {
    let parentId = d[config.parentId];
    if (nodeIds[parentId] == null) {
      tree.push(d);
    }
  }
  for (let t of tree) {
    adaptToChildrenList(t);
  }

  function adaptToChildrenList(o) {
    if (childrenListMap[o[config.id]] !== null) {
      o[config.childrenList] = childrenListMap[o[config.id]];
    }
    if (o[config.childrenList]) {
      for (let c of o[config.childrenList]) {
        adaptToChildrenList(c);
      }
    }
  }
  return tree;
}
export function subTime(time){
  if(time){
    let length = time.length;
    return time.substring(0,length-3)
  }else{
    return ""
  }
}
export function getDictAttributeByValue(list,key,value) {
  let _value = undefined
  list.map(item=>{
    if(item.value==value){
      _value = item[key]
    }
  })
  return _value
}
